package com.lelouch.wetlandcommon.tools;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import sun.misc.BASE64Encoder;

import java.security.MessageDigest;

/**
 * MD5 TOOL
 * Created by rencong on 2016/4/25.
 */
public class MD5Tool {
    static Logger logger = LoggerFactory.getLogger(MD5Tool.class);

    public  static String str2Md5(String str){
        try {
            //确定计算方法
            MessageDigest md5 = MessageDigest.getInstance("MD5");
            BASE64Encoder base64en = new BASE64Encoder();
            //加密后的字符串
            String pwdMd5 = base64en.encode(md5.digest(str.getBytes("utf-8")));
            return pwdMd5;
        }catch(Exception e){
            logger.error("字符串转MD5出现异常！", e);
            return null;
        }
    }


}
